<template>
	<view class="index">
		<view class="index_head">
		</view>
		<u-modal :show="show" :title="title" showCancelButton="true" @confirm="confirm" @cancel="cancel">
			<u--form labelPosition="left" :model="model1" :rules="rules" ref="form1">
				<u-form-item label="姓名" prop="userInfo.name" borderBottom ref="item1">
					<u--input v-model="model1.userInfo.name" border="none" placeholder="请输入姓名"></u--input>
				</u-form-item>
		
		
				<u-form-item label="手机" prop="userInfo.mobile" borderBottom ref="item1">
					<u--input v-model="model1.userInfo.mobile" border="none" disabled="true"></u--input>
		
					<u-button type="success" size="mini" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber"
						slot="right">获取手机号</u-button>
		
		
		
				</u-form-item>
			</u--form>
		
		</u-modal>
		<view class="index_title">
			<u-icon @click="gourl" index=1 label="约科列表" labelPos="bottom" size="40" name="/static/menu/news_2.png">
			</u-icon>
			<u-icon  @click="gourl" index=2 label="学员请假" labelPos="bottom" size="40" name="/static/menu/meet_1.png"></u-icon>
			<u-icon @click="gourl" index=3 label="加入会员" labelPos="bottom" size="40" name="/static/menu/news_3.png"></u-icon>
			<u-icon @click="gourl" index=4 label="公告" labelPos="bottom" size="40" name="/static/menu/news_1.png"></u-icon>
		</view>
		<view class="index_contnet">
			<view class="index_contnet_item" v-for="(item,index) in list" @click="Godetail(item.newsId)">
				<u-image width="100%" :showLoading="true" mode="widthFix" :src="src"></u-image>
				<view class="text">
					<view class="text_t">
						{{item.title}}
					</view>
					<view class="text_c">
						<u-parse :content="item.content" :tagStyle="style"></u-parse>
					</view>
					<view class="text_b">
						<view class="">
							{{dateFormat(item.updateTime) }}

						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getnewlist,
		getopenmembr,
		getPhone,
		getipi 
	} from "@/api/index.js"
	export default {
		data() {
			return {
				src: 'https://gitee.com/zhiyuede/img-bed/raw/master/auctCar/my_index_up.jpg',
				list: [],
				style: {
					// 字符串的形式

					image: 'display:none'
				},
				show:false,
				model1: {
					userInfo: {
						name: '',
						mobile: ''
				
					},
				},
				rules: {
					'userInfo.name': {
						type: 'string',
						required: true,
						message: '请填写姓名',
						trigger: ['blur', 'change']
					},
					'userInfo.mobile': {
						type: 'string',
						required: true,
						message: '请获取手机号',
						trigger: ['blur', 'change']
					},
				},
			}
		},
		components: {

		},
		
		onLoad() {
			 let app = getApp();
					        this.userLoginFlag = app.globalData.userLogin;
					       	console.log(app.globalData.userLogin);
		},
		onShow() {
			let that = this
			that.getnewlists()
		},
		methods: {
			async getnewlists() {
				const {
					data,
					status,
					msg
				} = await getnewlist({
					params: {
						pageNum: 1,
						isHome: 1
					}
				})

				if (status == 200) {
					this.list = data.list

				}

			},
			confirm() {
				// 如果有错误，会在catch中返回报错信息数组，校验通过则在then中返回true
				this.$refs.form1.validate().then(res => {
					this.getipis()
					this.show = false
			
			
			
			
				}).catch(errors => {
					console.log(errors);
					uni.$u.toast('校验失败')
					return
				})
			
			},
			cancel() {
			
				this.show = false
			},
			async getopenmembrs() {
				let openid = uni.getStorageSync("openid")
				const {
					data,
					status,
					msg
				} = await getopenmembr({
					openid
				})
				
				if (status == 200) {
					uni.showToast({
						title: '发起会员请求成功请联系管理员微信进行审核',
						duration: 2000,
						icon:"none"
					});
			
				}else{
					uni.showToast({
						title: '请重试',
						duration: 2000,
						icon:"none"
					});
				}
			
			},
			Godetail(e) {
				console.log(e);
				uni.navigateTo({
					url: '/pages/user/detail/detail?newsid=' + e
				})
			},
			gourl(index) {
				
				if (index == 1) {
					uni.switchTab({
						url:'/pages/hall/hall'
					})
				}
				if(index == 2){
					console.log(index);
					uni.navigateTo({
						url:'/pages/user/isappliAll/isappliAll?type='+1
					})
				}
				if(index==3){
					this.show = true
					
					
				}else{
					uni.switchTab({
						url:'/pages/price/price'
					})
				}
			},
			dateFormat(time) {
				let date = new Date(time);
				let year = date.getFullYear();
				// 在日期格式中，月份是从0开始的，因此要加0，使用三元表达式在小于10的前面加0，以达到格式统一  如 09:11:05
				let month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
				let day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
				let hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
				let minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
				let seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
				// 拼接
				return year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;
				// return year + "-" + month + "-" + day;
			},
async getPhoneNumber(e) {
				console.log(e);
				const {
					data,
					status,
					msg
				} = await getPhone({
					code: e.detail.code
				})
				if (status == 200) {
					this.model1.userInfo.mobile = data
				}

			},
	async getipis() {
				let openid = uni.getStorageSync('openid')

				const {
					data,
					status,
					msg
				} = await getipi({
					openId: openid,
					nickName: this.model1.userInfo.name,
					mobile: this.model1.userInfo.mobile
				})

				if (status == 200) {
					let userifro = uni.getStorageSync("userinfo")
					
					if(userifro.athCheckId == 1){
						uni.showToast({
							title: '请不要重复开通或申请',
							duration: 2000,
							
						});
					}else{
						this.getopenmembrs()
					}
				}
			},
		},
	}
</script>

<style lang="scss" scoped>
	page {
		height: 100vh;
		background-color: #4f4a73;
	}

	.index {

		background-color: #4f4a73;

		.index_head {
			height: 500rpx;
			width: 100%;
			background-image: url("@/static/default_index_bg1.jpg");
			background-size: 100% 120%;
			position: relative;
			border-radius: 0rpx 0rpx 50rpx 50rpx;

		}

		.index_title {
			position: absolute;
			transform: translate(-50%);
			left: 50%;
			top: 400rpx;
			background-color: #fff;
			display: flex;
			padding: 50rpx;
			width: 95%;
			box-sizing: border-box;
			border-radius: 25rpx;
			justify-content: space-between;
		}

		.index_contnet {
			width: 95%;
			margin: 0rpx auto;
			margin-top: 150rpx;
			padding-bottom: 40rpx;

			.index_contnet_item {
				overflow: hidden;
				border-radius: 25rpx;
				background-color: #fff;
				width: 100%;
				height: 610rpx;
				margin-bottom: 40rpx;

				.text {
					color: $u-main-color;
					padding: 10rpx;

					.text_t {
						font-weight: 800;
					}

					.text_c {
						color: $u-content-color;

						display: -webkit-box; //对象作为弹性伸缩盒子模型显示
						overflow: hidden; //溢出隐藏
						-webkit-box-orient: vertical; //设置伸缩盒子对象的子元素的排列方式
						-webkit-line-clamp: 2; //设置 块元素包含的文本行数

						/deep/ image {
							display: none;
						}
					}

					.text_b {
						color: $u-content-color;
						text-align: end;
						padding-right: 40rpx;
						margin-bottom: 20rpx;
					}
				}
			}
		}
	}
</style>
